<template>
  <div>
    {{aa}}
    <!-- {{list}} -->

    <el-container v-for="(i,x) in list" :key="x">
  <el-aside width="500px"><img :src="i.url" alt="" width="500px" height="500px"></el-aside>
  <el-main>
    <h2> {{i.descs}}</h2>
    <h4>
    {{i.money}}</h4>
      <span>销量{{i.sales}}</span>
    <el-button @click="buy(i.id)">购买</el-button>
  </el-main>
    
</el-container>


  </div>
</template>

<script>
import { Toast } from 'vant';
export default {
    data(){
        return{
            userid:localStorage.getItem('userid'),
            list:[],
            aa:this.$route.path,
            list1:""
        }
    },
    methods:{
        getgoods(){
            this.axios.get('getgoods?userid='+this.userid)
            .then(res=>{
                this.list = res.data.data
            })
        },
          methods: {
    onClickIcon() {
      Toast('点击图标');
    },
    onClickButton() {
      Toast('点击按钮');
    },
  },
  buy(id){
    this.axios.post('postorder',{id:id,userid:this.userid,token:this.list1})
    .then(res=>{
        alert(res.data.msg)
    })
  },
//   加入浏览记录
  getbrowsing(){
    this.axios.get('browsing?userid='+this.userid+'&url='+this.aa)
    .then(res=>{
        console.log(res)
    })
  },
  get_m_token(){
    this.axios.get('/m_token')
    .then(res=>{
        this.list1 = res.data.token
    })
  }
    },
    mounted(){
        this.getgoods()
        this.getbrowsing()
        this.get_m_token()
    }

}
</script>

<style>
 .el-header, .el-footer {
    background-color: #B3C0D1;
    color: #333;
    text-align: center;
    line-height: 60px;
  }
  
  .el-aside {
    background-color: #D3DCE6;
    color: #333;
    text-align: center;
    line-height: 100px;
  }
  
  .el-main {
    background-color: #E9EEF3;
    color: #333;
    text-align: center;
    line-height: 160px;
  }
  
  body > .el-container {
    margin-bottom: 40px;
  }
  
  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }
  
  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }

</style>